package com;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/login")
public class Login extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求乱码  设置响应乱码
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        //载入页面
        String log = "   <form action=\"/check\" method=\"get\">\n" +
                "        用户名：<input type=\"text\" name=\"username\">\n" +
                "        密码：<input type=\"password\" name=\"password\">\n" +
                "        <input type=\"submit\">\n" +
                "\n" +
                "    </form>";
        resp.getWriter().write(log);
        int a =0;
        ServletContext servletContext = req.getServletContext();
        servletContext.setAttribute("all",a);
        //判断是否为有账号登录过
        HttpSession session = req.getSession();
        if (session.getAttribute("user1") =="on"){
            req.getRequestDispatcher("/Welcome").forward(req,resp);
        }



    }
}
